#ifndef __FLUID_BLOCK_HPP__
#define __FLUID_BLOCK_HPP__

#include <cstdint>

#include "Block.hpp"
#include "Engine/Matrix.h"
#include "Engine/BoundingBox.hpp"
#include "Engine/MathUtils.hpp"

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
    class FluidBlock : public Block
    {
    protected:
        float m_heightByLevel[16] = { 0.0f };
        std::vector<BoundingBox> m_boundingBoxesByLevel[16];
        int32_t m_maxLevel;


    public:
        FluidBlock(int32_t maxLevel);
        virtual const std::vector<BoundingBox> &getCustomCollisionBoxes(int32_t value) override;
        virtual BlockPlacementData getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult) override;
        virtual bool isHeatBlocker(int32_t value) override;

        inline void setMaxFluidLevel(int32_t fluidLevel);
        inline int32_t getMaxFluidLevel();
        inline float getLevelHeight(int32_t level);

        static inline int32_t GetLevel(int32_t data);
        static inline int32_t SetLevel(int32_t data, int32_t level);
        static inline bool GetIsTop(int32_t data);
        static inline int32_t SetIsTop(int32_t data, int32_t isTop);
    };

    inline float FluidBlock::getLevelHeight(int32_t level)
    {
        return m_heightByLevel[level];
    }
    inline void FluidBlock::setMaxFluidLevel(int32_t fluidLevel)
    {
        m_maxLevel = fluidLevel;
    }
    inline int32_t FluidBlock::getMaxFluidLevel()
    {
        return m_maxLevel;
    }

    inline int32_t FluidBlock::GetLevel(int32_t data)
    {
        return data & 0xF;
    }
    inline int32_t FluidBlock::SetLevel(int32_t data, int32_t level)
    {
        return (data & -16) | ( level & 0xF);
    }
    inline bool FluidBlock::GetIsTop(int32_t data)
    {
        return (data & 0x10) != 0;
    }
    inline int32_t FluidBlock::SetIsTop(int32_t data, int32_t isTop)
    {
        if(isTop == false)
        {
            return data & -17;
        }
        return data | 0x10;
    }

} // namespace PocketSurvival

#endif